# # from app.order.purchase.abs_model import PurchaseOrder
# # from app.order.purchase.model import PurchaseOrder as PurchaseOrderTable
# # from exts import db
# # from app.order.purchase import dao
# # from common.utils.utils import custom_marshal_pagination
# #
# #
# # def create(user_id, order_skus_json, **kwargs):
# #     """"""
# #     purchase_order = PurchaseOrder()
# #     return purchase_order.create_order(user_id, order_skus_json, **kwargs)
# #
# #
# # def get_by_page(user_id, **kwargs):
# #     pagination = dao.get_by_page(**kwargs)
# #     pagination = custom_marshal_pagination(pagination)
# #     return pagination
# #
# #
# # def get(user_id, obj_id):
# #     return PurchaseOrderTable.query.filter_by(id=obj_id).first()
# #
# #
# # def save_draft(user_id, order_id, order_skus_json, **kwargs):
# #     """"""
# #     purchase_order = PurchaseOrder(order_id, user_id)
# #     purchase_order.save_draft(order_skus_json, **kwargs)
# #     return purchase_order.order_table
# #
# #
# # def submit(user_id, order_id, order_skus_json, **kwargs):
# #     purchase_order = PurchaseOrder(order_id, user_id)
# #     purchase_order.save_draft(order_skus_json, **kwargs)
# #     purchase_order.submit()
# #     return purchase_order.order_table
# #
# #
# # def revoke(user_id, order_id):
# #     purchase_order = PurchaseOrder(order_id, user_id)
# #     purchase_order.revoke()
# #     return purchase_order.order_table
# #
# #
# # def delete(user_id, obj_id):
# #     obj = PurchaseOrder.query.filter_by(id=obj_id).first()
# #     db.session.delete(obj)
# #     db.session.commit()
# #     return obj.id
# #
# #
# from common.decorators import catch_error
# from app.order.purchase import service
# from app.user.decorators import token_required
# from common.responses import ok
# from flask_restplus import Resource, Namespace, fields, marshal, reqparse, Model
#
# from common import constant
# from flask import g
# # from app.order.response_model import purchase_order_model
# from app.order.request_parser import get_parser
# from app.order.purchase.model import PurchaseOrder, PurchaseOrderSku
# from app.order.purchase import dao
# from exts import db
# from app.file.model import FileRelation, File
# from app.file.controller import file_model
# from datetime import datetime
# from app.customer.controller import customer_model
# from app.storage.warehouse.controller import warehouse_model
# from app.finance.account.controller import account_model
# from app.product.sku.controller import sku_model
# from app.product.unit.controller import unit_model
# from app.file.service import get_img_files_from_belong
#
#
# # def get_default_date(date):
# #     if not date:  # 如果没有填写单据日期，默认使用当天的日期，作为单据日期
# #         return datetime.now().strftime('%Y-%m-%d')
# #     return date
#
#
#
#
# # def create_purchase_order(order_skus, image_ids, date, action, **kwargs):
# #     """创建采购单"""
# #     if not date:  # 如果没有填写单据日期，默认使用当天的日期，作为单据日期
# #         kwargs['date'] = datetime.now().strftime('%Y-%m-%d')
# #     # 创建order
# #     new_purchase_order = PurchaseOrder.create(
# #         **kwargs,
# #         order_sn=PurchaseOrder.generate_order_sn(),
# #         commit=True
# #     )
# #     # 创建order_sku
# #     for order_sku_json in order_skus:
# #         PurchaseOrderSku.create(
# #             order_id=new_purchase_order.id,
# #             **order_sku_json,
# #         )
# #     # images
# #     if image_ids or len(image_ids) == 0:
# #         for image_id in image_ids:
# #             FileRelation.create(
# #                 file_id=image_id, belong_id=new_purchase_order.id,
# #                 belong_type=constant.FileBelongType.PURCHASE_ORDER)
# #
# #     if action == constant.OrderActionType.SUBMIT:
# #         new_purchase_order.submit()
# #
# #     db.session.commit()
# #     return new_purchase_order